package com.jic.member.impl;

import com.jic.common.base.vo.RestResult;
import com.jic.manager.api.manage.SysDeptApi;
import com.jic.manager.request.MerchantRequest;
import com.jic.manager.response.MemMerchantInfoResponse;
import com.jic.manager.service.SysDeptService;
import com.jic.member.request.MemberScopeApplicationRequest;
import com.jic.member.service.MemberScopeApplicationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MemberScopeApplicationServiceImpl implements MemberScopeApplicationService {

    private SysDeptService sysDeptApi;

    @Override
    public RestResult<Long> insert(MemberScopeApplicationRequest memberScopeApplicationRequest) {
        MerchantRequest merchantRequest = new MerchantRequest();
        merchantRequest.setId(memberScopeApplicationRequest.getAdminOperate().getMerchantIds().get(0));
        merchantRequest.setWhetherApplication(memberScopeApplicationRequest.getWhetherApplication());
        merchantRequest.setScopeApplication(memberScopeApplicationRequest.getScopeApplication());
        return sysDeptApi.updateMerchantScopeApplicationById(merchantRequest);
    }

    @Override
    public MemMerchantInfoResponse getGrowhtScopeInfo(MemberScopeApplicationRequest memberScopeApplicationRequest) {
        Integer deptType = memberScopeApplicationRequest.getAdminOperate().getDeptType().getCode();
        if (deptType != 1 && deptType != 0) {
            Long merchantId = memberScopeApplicationRequest.getAdminOperate().getMerchantIds().get(0);
            return sysDeptApi.getGrowhtScopeInfo(merchantId);
        } else {
            MemMerchantInfoResponse memMerchantInfoResponse = new MemMerchantInfoResponse();
            memMerchantInfoResponse.setScopeApplication(0L);
            return memMerchantInfoResponse;
        }
    }
}
